package cn.wen.javax.servlet.jsp.tagext.form;

import java.util.List;
import java.util.Map;

import javax.servlet.jsp.JspException;

import cn.wen.javax.servlet.jsp.tagext.AbstractTag;
import cn.wen.javax.servlet.jsp.tagext.builder.form.SelectBuilder;

public class SelectTag extends AbstractTag {

    private static final long serialVersionUID = -8530038690177783119L;

    public SelectTag() {
	super();
    }

    @Override
    public int doStartTag() throws JspException {
	builder = new SelectBuilder(this);
	return super.doStartTag();
    }

    @Override
    public int doEndTag() throws JspException {
	builder.process();
	builder.render(this.pageContext.getOut());
	return super.doEndTag();
    }

    // ---------------------------------------------------------------------
    // this tag Attributes
    // ---------------------------------------------------------------------

    private Object value;

    private boolean showAll = false;

    private List<Map<String, ?>> options = null;

    public void setShowAll(boolean showAll) {
	this.showAll = showAll;
    }

    public boolean isShowAll() {
	return showAll;
    }

    public Object getValue() {
	return value;
    }

    public void setValue(Object value) {
	if (value == null) return;
	this.value = this.valueStack.findValue(value.toString());
    }

    public List<Map<String, ?>> getOptionList() {
	return options;
    }

    public void setOptions(String options) {
	this.options = (List<Map<String, ?>>) this.valueStack.findValue(options);
    }

}
